//
// Created by isabella on 25-6-2.
//
#include <common.h>

class TNode {
public:
    TNode *left;
    TNode *right;
    int data;
    int ltag;
    int rtag;


    TNode() = default;

    explicit TNode(int element) {
        data = element;
        left = nullptr;
        right = nullptr;
        ltag = 0;
        rtag = 0;
    }
};

class Solution {
public:
    TNode *pre;
    TNode *memo;
    TNode* _root;

    Solution(TNode* root) {
        _root = root;
        pre = nullptr;
        memo = nullptr;

        inorder(root);
        if(pre!=nullptr&&pre->right==nullptr) {
            pre->rtag=1;
        }
    }

    void inorder(TNode *root) {
        if (root == nullptr) {
            return;
        }
        inorder(root->left);
        visit(root);
        inorder(root->right);
    }

    void visit(TNode *root) {
        if (root == nullptr) {
            return;
        }
        if(root->left==nullptr) {
            root->ltag=1;
            root->left=pre;
        }
        if(pre!=nullptr&& pre->right==nullptr) {
            pre->right=root;
            pre->rtag=1;
        }
        pre=root;
    }
};

int main() {
    return 0;
}
